<?php

namespace api\wxapp\controller;
use cmf\controller\RestBaseController;
use think\Db;


/**
 *Title:默认信息
 *<br/>By: 王龙 2022/8/29 17:44
 */

class IndexController extends  RestBaseController{


    /**
     * 1 正式 0 审核 12322 123
     * @return void
     */
    public function test(){

        $this->success('是否展示',['show'=>1]);
    }

    /**
     * 验证信息
     */
    public function getcodes(){




        $info=Db::name('aa_tame_set')->find();
        $info['downs']=explode(',',$info['downs']);


        $this->success('验证信息',$info);
    }

    /**
     * 团队商品
     */
    public function gettamegoods(){

        $info=Db::name('aa_tame_good')->select()->toArray();


        foreach ($info as &$key){
            $downs=explode(',',$key['goods']);
            $downarrs=[];
            foreach ($downs as $down){

                $downarr['name']=$down;
                $downarr['count']=0;

                $downarrs[]=$downarr;
            }
            $key['down']=$downarrs;
        }

        $this->success('团队商品',$info);
    }

    /**
     * @return void
        首页信息
     */
    public function indexlist(){

        $userinfo=$this->user;

        if (!$userinfo){
            $this->error(['code' => 10001, 'msg' => '用户未登录']);
        }

        $user=Db::name('user')->where(['id'=>$userinfo['id']])->find();

        $team_id=$user['team_id'];

        $list=Db::name('aa_goods')->where('id','gt',0)
        ->where('endtime','gt',time())
            ->where('team_id','like','%'.$team_id.'%')
        ->limit(99)->order('order desc,id desc')->select()->toArray();

        foreach ($list as &$key){
            $key['times']=date('Y-m-d H:i',$key['times']);
        }

        $this->success('首页信息',$list);

    }


    /**
        查询相商品关订单
     */
    public function getorderbygid(){

        $gid=$this->request->param('id');

        $list=Db::name('aa_order')->where(['gid'=>$gid])->select()->toArray();

        foreach ($list as &$key){

            $user=Db::name('user')->where(['id'=>$key['uid']])->find();

            $key['username']=$user['name'];
            $key['usermobile']=$user['mobile'];
            $key['avatar']=$user['avatar'];
            $key['times']=date('Y-m-d H:i',$key['times']);
        }

        $this->success('订单信息',$list);

    }



    public function getbanner(){

        $list=Db::name('slide_item')->where(['status'=>1])->select()->toArray();

        foreach ($list as &$key){
            $key['image']=cmf_get_image_url($key['image']);
        }


        $this->success('首页banner',$list);

    }


    public function getabout(){

        $list=Db::name('aa_about')->where(['id'=>1])->find();

        $list['value']=cmf_replace_content_file_url($list['value']);

        $this->success('about',$list);

    }

    //团队信息
    public function getallteam(){

        $list=Db::name('aa_hezuo')->where(['status'=>1])->select()->toArray();



        $this->success('团队信息',$list);
    }

    /**
    商品信息 团队用
     */
    public function indexlistbypage(){

        $page=$this->request->param('page');
        $limits=($page-1)*10 . ',15';

        $id=$this->getUserId();

        $user=Db::name('user')->where(['id'=>$id])->find();

        $list=Db::name('aa_goods')
            ->where('id','gt',0)
            ->where('team_id','eq',$user['team_id'])
            ->limit($limits)
            ->order('id desc')
            ->select()->toArray();

        foreach ($list as &$key){
            $key['times']=date('Y-m-d H:i',$key['times']);
        }

        $this->success('首页信息',$list);

    }



}